package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.THospitalOffice;
import com.ruoyi.project.system.service.ITHospitalOfficeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 科室Controller
 * 
 * @author 孙山伟
 * @date 2020-12-20
 */
@RestController
@RequestMapping("/system/office")
public class THospitalOfficeController extends BaseController
{
    @Autowired
    private ITHospitalOfficeService tHospitalOfficeService;

    /**
     * 查询科室列表
     */
    @PreAuthorize("@ss.hasPermi('system:office:list')")
    @GetMapping("/list")
    public TableDataInfo list(THospitalOffice tHospitalOffice)
    {
        startPage();
        List<THospitalOffice> list = tHospitalOfficeService.selectTHospitalOfficeList(tHospitalOffice);
        return getDataTable(list);
    }
    /**
     * 查询科室列表
     */
    @PreAuthorize("@ss.hasPermi('system:office:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll(THospitalOffice tHospitalOffice)
    {
        List<THospitalOffice> list = tHospitalOfficeService.selectTHospitalOfficeList(tHospitalOffice);
        return AjaxResult.success(list);
    }
    /**
     * 导出科室列表
     */
    @PreAuthorize("@ss.hasPermi('system:office:export')")
    @Log(title = "科室", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(THospitalOffice tHospitalOffice)
    {
        List<THospitalOffice> list = tHospitalOfficeService.selectTHospitalOfficeList(tHospitalOffice);
        ExcelUtil<THospitalOffice> util = new ExcelUtil<THospitalOffice>(THospitalOffice.class);
        return util.exportExcel(list, "office");
    }

    /**
     * 获取科室详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:office:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tHospitalOfficeService.selectTHospitalOfficeById(id));
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('system:office:add')")
    @Log(title = "科室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody THospitalOffice tHospitalOffice)
    {
        return toAjax(tHospitalOfficeService.insertTHospitalOffice(tHospitalOffice));
    }

    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('system:office:edit')")
    @Log(title = "科室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody THospitalOffice tHospitalOffice)
    {
        return toAjax(tHospitalOfficeService.updateTHospitalOffice(tHospitalOffice));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('system:office:remove')")
    @Log(title = "科室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tHospitalOfficeService.deleteTHospitalOfficeByIds(ids));
    }
}
